/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 *
 */

export function strMapToObj(strMap: Map<string, any>) {
  const obj = Object.create(null);
  for (const [k, v] of strMap) {
    if (v instanceof Map) {
      obj[k] = strMapToObj(v);
    } else {
      obj[k] = v;
    }
  }
  return obj;
}

export function getMapKeyArr(map: Map<string, any>): string[] {
  const keyArr: string[] = [];
  keyArr.push(...map.keys());
  return keyArr;
}

export function objToStrMap(obj: any) {
  const strMap = new Map();
  for (const k of Object.keys(obj)) {
    strMap.set(k, obj[k]);
  }
  return strMap;
}

export function parseValue(value: string): string | number | boolean {
  if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
    return value.toLowerCase() === 'true';
  } else if (!isNaN(Number(value))) {
    return Number(value);
  } else {
    return value;
  }
}
